<?php
if(isset($_POST['createAuth'])){
	
	if(isset($_GET['action'])){
		
		foreach($_POST as $key => $value){
			
			if($key == "createAuth"){

				continue;
				
			}
			
			$sArr[$key] = $value;
			
		}
		
		//print "<pre>"; print_r($sArr); print "</pre>";
		
		if($lpcp->getLPCPClient()->updateService($_GET['action'],$sArr,$sArr['message'])){
			
			$success = 'updated';
			
		}else{
			
			$_SESSION['error']['clientcreate'] = "Could not create new client account";
			
		}
		
	}elseif(isset($_GET['action']) && $_GET['action'] == "add" && !empty($_POST)){
		
		foreach($_POST as $key => $value){
			
			if($key == "createAuth"){

				continue;
				
			}
			if(empty($value) && $key != "cid"){
				
				$cArr = NULL;
				break;
				
			}else{

				$cArr[$key] = $value;

			}
		}

		if(!empty($cArr)){
			if($lpcp->getLPCPClient()->createClient($cArr)){
				
				$success = 'created';
				
			}else{
				
				$_SESSION['error']['clientcreate'] = "Could not create new client account";
				
			}
		}else{
				
			$_SESSION['error']['clientcreate'] = "Could not create new client account";
				
		}
		
	}else{
		
		$_SESSION['error']['clientcreate'] = "Error in information";
		
	}
	
}

	if(isset($_GET['action']) && isset($_GET['var'])){

		$cData = $lpcp->getLPCPClient()->fetchServiceData($_GET['var']);

	}

	if($_GET['action'] == "edit"){
		
		print "<h3>Edit Client Service</h3>";
		
	}

	if(isset($_SESSION['error']['usercreate']) && !empty($_SESSION['error']['usercreate'])){
		
		print "<i id='error'>".$_SESSION['error']['usercreate']."</i>";
		unset($_SESSION['error']);
		
	}
	
	if($success){
		print "<i id='success'>Successfully ".$success." services!</i>";
		unset($success);
		
	}
?>